package com.itheima.xuanze;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int arr[] = {9, 5, 4, 6, 10, 11, 7, 8, 2};
        int count = 0;
        for (int i = 0; i < arr.length - 1; i++) {
            //外层循环：控制比较的轮数
            //记录最小值的索引
            int min = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[min] > arr[j]) {
                    min = j;
                }
            }
            if (min != i) {
                swap(arr,i,min);
                count++;
            }
        }
        System.out.println("交换次数：" + count);
        System.out.println("排序结构：" + Arrays.toString(arr));
    }

    private static void swap(int[] arr, int i, int j) {

        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];


    }
}
